<template>
  <z-modal
    :width="modalWidth"
    :visible="visible"
    :title="title"
    destroyOnClose
    switchFullscreen
    @ok="handleSubmit"
    @cancel="close"
    cancelText="关闭"
  >
    <a-card :bordered="false">
      <a-form @keyup.enter.native="searchQuery">
        <a-row :gutter="24">
		  <a-col :md="6" :sm="12">
		    <a-form-item label="商机名称" :labelCol="labelCol" :wrapperCol="wrapperCol">
		      <a-input style="width:100%;" placeholder="请输入商机名称" v-model="queryParam.name"></a-input>
		    </a-form-item>
		  </a-col>
          <a-col :span="4">
            <a-form-item>
              <a-button type="primary" icon="reload" style="margin-left: 8px" @click="searchReset()">重置</a-button>
            </a-form-item>
          </a-col>
        </a-row>
      </a-form>
      <!--商机列表-->
      <vxe-grid
        id="selectBusinessList"
        ref="vxeTable"
        :toolbarConfig="false"
        :checkbox-config="{trigger:this.multi?'row':'cell'}"
        :radio-config="{trigger:!this.multi?'row':'cell'}"
        :rowConfig="{ keyField: 'id',isCurrent:true }"
        v-bind="gridOptions"
        v-on="listeners"
        @radio-change="onRadioSelectChange"
      >
      </vxe-grid>
    </a-card>
  </z-modal>
</template>

<script>
import VxeTableListMixin from '@/mixins/VxeTableListMixin'

export default {
  name: 'SelectBusinessModal',
  mixins: [VxeTableListMixin],
  props: {
    modalWidth: {
      type: Number,
      default: 1250,
      required: false
    },
    multi: {
      type: Boolean,
      default: false,
      required: false
    },
  },
  data() {
    return {
      title: '选择商机',
      loading: false,
      form: this.$form.createForm(this),
      visible: false,
      columns: [
        { type: this.multi ? 'checkbox' : 'radio', width: 50 },
        { type: 'seq', width: 40 },
		{
		  title:'商机名称',
		  align:"center",
		  width: 150,
		  field: 'businessName'
		},
		{
		  title:'项目名称',
		  align:"center",
		  field: 'productId',
		  width: 200,
		  formatter: 'dictText'
		},
		{
		  title:'客户名称',
		  align:"center",
		  field: 'customerId',
		  width: 200,
		  formatter: 'dictText'
		},
		{
		  title:'消息来源',
		  align:"center",
		  field: 'source',
		  width: 100,
		  formatter: 'dictText'
		},
		{
		  title:'客户类型',
		  align:"center",
		  width: 100,
		  field: 'crmCustomer.textMap.customerType$DICT_TEXT_'
		},
		{
		  title:'跟进公司',
		  align:"center",
		  width: 150,
		  field: 'companyName'
		},
		{
		  title:'跟进部门',
		  align:"center",
		  field: 'deptId',
		  width: 150,
		  formatter: 'dictText'
		},
		{
		  title:'商机归属人',
		  align:"center",
		  field: 'ownerUserId',
		  width: 150,
		  formatter: 'dictText'
		},
		{
		  title:'预估合同总额',
		  align:"center",
		  width: 150,
		  field: 'money'
		},
		{
		  title:'销售阶段',
		  align:"center",
		  field: 'statusId',
		  width: 100,
		  formatter: 'dictText'
		}
      ],
      url: {
        list: "/business/list",
      },
    }
  },
  methods: {
    // async loadTableData() {
    //   this.loading = true
    //   var params = this.getQueryParams()// 查询条件
    //   let res
    //   if (this.selectedDepIds && this.selectedDepIds.length > 0) {
    //     res = await this.initQueryUserByDepId(this.selectedDepIds, params)
    //   } else {
    //     res = await userList(params)
    //   }
    //   this.loading = false
    //   return res
    // },
    showModal() {
      this.visible = true
      this.loadData()
      this.form.resetFields()
    },
    close() {
      this.searchReset(0)
      this.visible = false
    },
    handleSubmit() {
      this.$emit('ok', this.selectionRows, this.selectedRowKeys)
      this.close()
    },
    searchQuery() {
      this.loadData('reload')
    },
    onRadioSelectChange({ row }) {
      this.selectionRows = [row]
      this.selectedRowKeys = [row.num]
    }
  }
}
</script>
